package com.dailyblue.java.boot.security.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dailyblue.java.boot.security.project.bean.Powers;
import com.dailyblue.java.boot.security.project.mapper.PowersMapper;
import com.dailyblue.java.boot.security.project.service.PowersService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class PowersServiceImpl extends ServiceImpl<PowersMapper, Powers> implements PowersService {
    @Resource
    private PowersMapper powersMapper;

    @Transactional(rollbackFor = Exception.class)
    public void updatePowerByUserId(int uid, int[] pid) {
        powersMapper.deletePowerByUserId(uid);
        for (int i = 0; i < pid.length; i++) {
            powersMapper.savePower(uid, pid[i]);
        }
    }
}
